package com.hdaccp.shop.controller;

import com.hdaccp.pojo.po.Shop;

import com.hdaccp.shop.dao.ShopDao;

import com.hdaccp.shop.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private ShopDao shopDao;
    @Autowired
    private ShopService shopService;
//    @Autowired
//    private DingdanDao dingdanDao;
//    @Autowired
//    private DingdanxqDao dingdanxqDao;

    @RequestMapping("/query")
    public List<Shop> query(){
        return shopDao.findAll();
        
    }
    @RequestMapping("/getOne/{shopId}")
    public Shop getOne(@PathVariable("shopId") int shopId){
        return shopDao.findById(shopId).get(); 
    }
    @RequestMapping("/queryPage/{cpage}/{pagesize}")
    public List<Shop> queryPage(@PathVariable("cpage") int cpage,@PathVariable("pagesize") int pagesize){
        return shopService.queryPage(cpage,pagesize );
        }
    @RequestMapping("/save/{shopname}/{shopmoney}/{shopimg}/{shoptypeId}/{shopcailiaoId}/{cailiao}/{baozhuang}/{huayu}/{fusong}")
    public String save(@PathVariable("shopname") String shopname,@PathVariable("shopmoney") double shopmoney,@PathVariable("shopimg")
    String shopimg,@PathVariable("shoptypeId") int shoptypeId,@PathVariable("shopcailiaoId") int shopcailiaoId,@PathVariable("cailiao") String cailiao,@PathVariable("baozhuang") String baozhuang,@PathVariable("huayu") String huayu,@PathVariable("fusong") String fusong){
       String message="成功了";
        Shop shop=new Shop();
        shop.setShopname(shopname);
        shop.setShopmoney(shopmoney);
        shop.setShopimg(shopimg);
        shop.setShoptypeId(shoptypeId);
        shop.setShopcailiaoId(shopcailiaoId);
        shop.setCailiao(cailiao);
        shop.setBaozhuang(baozhuang);
        shop.setHuayu(huayu);
        shop.setFusong(fusong);
        try {
            shopDao.save(shop);
        } catch (Exception e){
            message="失败了";
        }

return message;
    }


    @RequestMapping("/updata/{shopId}/{shopname}/{shopmoney}/{shopimg}/{shoptypeId}/{shopcailiaoId}/{cailiao}/{baozhuang}/{huayu}/{fusong}")
    public String updata(@PathVariable("shopId") int shopId,@PathVariable("shopname") String shopname,@PathVariable("shopmoney") double shopmoney,@PathVariable("shopimg")
            String shopimg,@PathVariable("shoptypeId") int shoptypeId,@PathVariable("shopcailiaoId") int shopcailiaoId,@PathVariable("cailiao") String cailiao,@PathVariable("baozhuang") String baozhuang,@PathVariable("huayu") String huayu,@PathVariable("fusong") String fusong){
        String message="修改成功";
        Shop shop= shopDao.findById(shopId).get();


        shop.setShopname(shopname);
        shop.setShopmoney(shopmoney);
        shop.setShopimg(shopimg);
        shop.setShoptypeId(shoptypeId);
        shop.setShopcailiaoId(shopcailiaoId);
        shop.setCailiao(cailiao);
        shop.setBaozhuang(baozhuang);
        shop.setHuayu(huayu);
        shop.setFusong(fusong);
        try {
            shopDao.save(shop);
        } catch (Exception e){
            message="失败了";
        }


        return message;
    }
    @RequestMapping("/del/{shopId}")
    public String del(@PathVariable int shopId){
        String message="成功了";
        try {  

        shopDao.deleteById(shopId);
        } catch (Exception e){
            message="失败了";
        }
        return message;
    }


    //根据收藏Id查询商品收藏
    @RequestMapping("/getshopId/{shoucangId}")
    public List<Shop> getshopid(@PathVariable("shoucangId") int shoucangId){
        List<Shop> list=new ArrayList<>();
        list.add( shopDao.findById(shoucangId).get());
        return list;
    }

//    //根据id查询订单
//    @RequestMapping("/getdingdan/{uid}")
//    public List<Dingdan> queryDingdanBy(@PathVariable("uid") int uid){
//        return dingdanDao.findByuid(uid);
//    }
//
//    //查询所有订单
//    @RequestMapping("/dindanAll")
//    public List<Dingdan> queryAlldingdan() {
//        return dingdanDao.findAll();
//    }
//
//    //根据id查询订单
////    @RequestMapping("/deleteddid/{ddid}")
////    public List<Dingdan> queryDingdanByddid(@PathVariable("ddid") int ddid){
////        return dingdanDao.findByuid(ddid);
////    }
//    @RequestMapping("/deletedingdan/{ddid}")
//    public String yhsc(@PathVariable("ddid") String ddid ){
//        String msg="1";
//        try {
//            dingdanDao.deleteById(ddid);
//        } catch (Exception e) {
//            msg="2";
//            e.printStackTrace();
//        }
//        return msg;
//    }
//
//
//
//    //根据单号查询订单详情
//    @RequestMapping("/selectxq/{ddid}")
//    public String selectddxqddid(@PathVariable("ddid") String ddid){
//        return dingdanxqDao.findByddid(ddid);
//    }


}